﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Caching;
using System.IO;
using System.Xml;
using System.Xml.Linq;

using yncTech.Common;

/// <summary>
///Settings 的摘要说明
/// </summary>
public class yncSettings
{
    static yncSettings()
	{
        Initilize();
	}

    static void RemoveCacheCallBack(string key, object value, CacheItemRemovedReason reason)
    {
        Initilize();
    }

    static void Initilize()
    {
        string fileName = Path.Combine(ApplicationState.ApplicationPath, "Settings.xml");
        if (File.Exists(fileName))
        {
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.Load(fileName);
            //Admin Node
            XmlNode adminNode = xmldoc.SelectSingleNode("//root/Admin");
            AdminTitle = adminNode.SelectSingleNode("Title").InnerText;
            AdminTheme = adminNode.SelectSingleNode("Theme").InnerText;

            //set the session default timeout 30 minute
            int sessionTimeOut = 30;
            int.TryParse(xmldoc.SelectSingleNode("//root/SessionTimeOut").InnerText, out sessionTimeOut);
            SessionTimeOut = sessionTimeOut;
            Pagination.Load(xmldoc);

            Mail.Load(xmldoc);
        }
        HttpRuntime.Cache.Insert("yncTechWeb_Settings", "", new CacheDependency(fileName), DateTime.MaxValue,
            TimeSpan.Zero, CacheItemPriority.NotRemovable, new CacheItemRemovedCallback(RemoveCacheCallBack));
    }

    

    /// <summary>
    /// 分页
    /// </summary>
    public class Pagination
    {
        /// <summary>
        /// 加载Pagenation设置
        /// </summary>
        internal static void Load(XmlDocument xmldoc)
        {
            XmlNode pagnationNode = xmldoc.SelectSingleNode("//root/Pagination");
            Pagination.EmptyText = pagnationNode.SelectSingleNode("Empty_Text").InnerText;
            Pagination.TotalText = pagnationNode.SelectSingleNode("Total_Text").InnerText;
            Pagination.First = pagnationNode.SelectSingleNode("First").InnerText;
            Pagination.Last = pagnationNode.SelectSingleNode("Last").InnerText;
            Pagination.Previous = pagnationNode.SelectSingleNode("Previous").InnerText;
            Pagination.Next = pagnationNode.SelectSingleNode("Next").InnerText;
        }
        /// <summary>
        /// 空记录提示
        /// </summary>
        public static string EmptyText
        {
            get;
            private set;
        }
        public static string TotalText
        {
            get;
            private set;
        }
        public static string First
        {
            get;
            private set;
        }
        public static string Last
        {
            get;
            private set;
        }
        public static string Previous
        {
            get;
            private set;
        }
        public static string Next
        {
            get;
            private set;
        }

    }

    public class Common
    { /// <summary>
        /// 加载Pagenation设置
        /// </summary>
        internal static void Load(XmlDocument xmldoc)
        {
            XmlNode commonNode = xmldoc.SelectSingleNode("//root/Common");
          
        }
        /// <summary>
        /// 文件上传的默认路径
        /// </summary>
        public static string ArticleFileUpLoadPath
        {
            get;
            private set;
        }
        /// <summary>
        /// 可以上传文件的扩展名
        /// </summary>
        public static string FileExtension
        {
            get;
            private set;
        }
 
    }

    public class Mail
    {
        internal static void Load(XmlDocument xmldoc)
        {
            XmlNode commonNode = xmldoc.SelectSingleNode("//root/Mail/FinMove");

            FinMove.MailSubject = commonNode.SelectSingleNode("Subject").InnerText;
            FinMove.MailContent = commonNode.SelectSingleNode("Content").InnerText;

            commonNode = xmldoc.SelectSingleNode("//root/Mail/FinConfirm");

            FinConfirm.MailSubject = commonNode.SelectSingleNode("Subject").InnerText;
            FinConfirm.MailContent = commonNode.SelectSingleNode("Content").InnerText;

        }

        public static class FinMove
        {

            public static string MailSubject
            {
                get;
                set;
            }

            public static string MailContent
            {
                get;
                set;
            } 
        }

        public static class FinConfirm
        {
            public static string MailSubject
            {
                get;
                set;
            }

            public static string MailContent
            {
                get;
                set;
            }
        }

    }

    /// <summary>
    /// Admin Title
    /// </summary>
    public static string AdminTitle
    {
        get;
        private set;
    }

    public static string AdminTheme
    {
        get;
        private set;
    }

    /// <summary>
    /// The session timeout time(Default 30 Minute)
    /// </summary>
    public static int SessionTimeOut
    {
        get;
        private set;
    }

  
}